package org.firebug.common.tools.core;

/**
 * @Author: 张晓东
 */
public final class ASCiiTools {
    public static boolean isDigital(byte b) {
        return 0x30 <= b && b <= 0x39;
    }

    public static boolean isDigital(char c) {
        return 0x30 <= c && c <= 0x39;
    }

    public static byte toDigital(byte b) {
        return isDigital(b) ? b -= 0x30 : b;
    }

    public static char toDigital(char c) {
        return isDigital(c) ? c -= 0x30 : c;
    }

    public static boolean isUpperCase(byte b) {
        return 0x41 <= b && b <= 0x5A;
    }

    public static boolean isUpperCase(char c) {
        return 0x41 <= c && c <= 0x5A;
    }

    public static boolean isLowerCase(byte b) {
        return 0x61 <= b && b <= 0x7A;
    }

    public static boolean isLowerCase(char c) {
        return 0x61 <= c && c <= 0x7A;
    }

    public static byte toUpperCase(byte b) {
        return isLowerCase(b) ? (b -= 0x20) : b;
    }

    public static char toUpperCase(char c) {
        return isLowerCase(c) ? (c -= 0x20) : c;
    }

    public static byte toLowerCase(byte b) {
        return isUpperCase(b) ? (b += 0x20) : b;
    }

    public static char toLowerCase(char c) {
        return isUpperCase(c) ? (c += 0x20) : c;
    }

    public static boolean isLetter(byte b) {
        return isUpperCase(b) || isLowerCase(b);
    }

    public static boolean isLetter(char c) {
        return isUpperCase(c) || isLowerCase(c);
    }

    private ASCiiTools() {
    }
}
